<template>
  <div>
    <el-row type="flex" justify="end">
      <el-select
        v-model="currentYear"
        size="small"
        style="width: 120px"
        @change="dateChange"
      >
        <el-option
          v-for="item in yearList"
          :key="item"
          :label="item"
          :value="item"
          >{{ item }}</el-option
        >
      </el-select>
      <el-select
        v-model="currentMonth"
        size="small"
        style="width: 120px;margin-left:10px"
        @change="dateChange"
      >
        <el-option v-for="item in 12" :key="item" :label="item" :value="item">{{
          item
        }}</el-option>
      </el-select>
    </el-row>
    <el-calendar v-model="currentDate">
      <template slot="dateCell" slot-scope="{ date}">
        <div class="date-content">
          <!-- <span>{{ day | getDay }}</span> -->
          <span>{{ date.getDate() }}</span>

          <span v-if="isWeek(date)" class="rest">休</span>
        </div>
      </template>
    </el-calendar>
  </div>
</template>

<script>
export default {
  filters: {
    getDay(value) {
      // console.log(value, 888);
      var day = value.split("-")[2];
      var day2 = day.startsWith("0") ? day.substr("1") : day;
      return day2;
    }
  },
  props: {
    startDate: {
      type: Date,
      default: () => new Date()
    }
  },
  created() {
    console.log(this.startDate, 888);
    this.currentYear = this.startDate.getFullYear(); //  获取当前年
    this.yearList = Array.from(Array(11), (v, i) => i + this.currentYear - 5); //  根据当前年获取前后5年
    this.currentMonth = this.startDate.getMonth() + 1;
  },

  data() {
    return {
      currentMonth: null, // 当前月份
      currentYear: null, // 当前年份
      currentDate: null,
      yearList: []
    };
  },
  methods: {
    dateChange() {
      //console.log(111);
      //   this.currentYear=
      //   this.currentMonth =

      this.currentDate = new Date(`${this.currentYear}-${this.currentMonth}-1`); // 以当前月的1号为起始
    },

    isWeek(data) {
      if (data.getDay() == "0" || data.getDay() == "6") {
        return true;
      } else {
        return false;
      }
    }
  }
};
</script>

<style scoped>
/deep/ .el-calendar-day {
  height: auto;
}
/deep/ .el-calendar-table__row td,
/deep/ .el-calendar-table tr td:first-child,
/deep/ .el-calendar-table__row td.prev {
  border: none;
}
.date-content {
  height: 40px;
  text-align: center;
  line-height: 40px;
  font-size: 14px;
}
.date-content .rest {
  color: #fff;
  border-radius: 50%;
  background: rgb(250, 124, 77);
  width: 20px;
  height: 20px;
  line-height: 20px;
  display: inline-block;
  font-size: 12px;
  margin-left: 10px;
}
.date-content .text {
  width: 20px;
  height: 20px;
  line-height: 20px;
  display: inline-block;
}
/deep/ .el-calendar-table td.is-selected .text {
  background: #409eff;
  color: #fff;
  border-radius: 50%;
}
/deep/ .el-calendar__header {
  display: none;
}
</style>
